/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2019 FMSH.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by FM under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>  
#include "systick.h"
#include "bsp_usart.h"
#include "LsdPublicUse.h"

#include "gd32f30x_libopt.h"


typedef struct
{
	uint16_t softVer;//软件版本
	uint16_t hardVer;//硬件版本
	uint16_t chipType;//芯片型号
	uint8_t  boardType;//板子型号
	uint8_t  flag;//标记
}TypeChipInfo;


#define false FALSE 
#define true TRUE
typedef enum 
{
  HAL_OK       = 0x00U,
  HAL_ERROR    = 0x01U,
  HAL_BUSY     = 0x02U,
  HAL_TIMEOUT  = 0x03U
} HAL_StatusTypeDef;

/** 
  * @brief  GPIO Bit SET and Bit RESET enumeration 
  */
/* USER CODE BEGIN ENUM 全局枚举 */
typedef enum
{
  GPIO_PIN_RESET = 0U,
  GPIO_PIN_SET
}GPIO_PinState;

#define DEV_SOFT_VER    195//设备软件版本
#define DEV_HARD_VER    100//设备硬件版本 
#define DEV_CHIP_TYPE   1001//代表是GD32F303VC
#define DEV_TYPE        0x50//代表是控制板程序
#define CHIP_INFO_FALG  0x5a//芯片信息标识   


//@7
#define TEST_MODE 0//测试模式
#define DEV_DEVICE_TOP  "114"//设备号前3位

//#define DEF_IWDT 1 //看门狗
void Error_Handler(void);

#define PRODUCT_ID_NUM  517496 //产品ID


//@7转化为兆易
/****************************IO输出***********************************************/
//增压泵 冲洗阀 源水进水阀 纯水箱进水阀 纯水箱出水阀 热罐进水阀 热罐出水阀
#define BOOST_PUMP_CTRL_Pin 								GPIO_PIN_12     //增压泵
#define BOOST_PUMP_CTRL_GPIO_Port 					GPIOA

#define WASH_CTRL_Pin 						  				GPIO_PIN_6     //冲洗阀
#define WASH_CTRL_GPIO_Port 								GPIOC

#define SOURCE_IN_CTRL_Pin 						  	  GPIO_PIN_8     //源水进水
#define SOURCE_IN_CTRL_GPIO_Port 						GPIOA

#define PURE_TANK_IN_CTRL_Pin 							GPIO_PIN_9		 //纯水箱进水控制阀
#define PURE_TANK_IN_CTRL_GPIO_Port 				GPIOC

#define PURE_TANK_OUT_CTRL_Pin 							GPIO_PIN_7		 //纯水箱出水控制阀
#define PURE_TANK_OUT_CTRL_GPIO_Port 				GPIOC 

#define HEAT_TANK_IN_CTRL_Pin 							GPIO_PIN_8		 //热罐进水控制阀
#define HEAT_TANK_IN_CTRL_GPIO_Port 				GPIOC    

#define HEAT_TANK_OUT_CTRL_Pin 							GPIO_PIN_15		 //热罐出水控制阀   备用
#define HEAT_TANK_OUT_CTRL_GPIO_Port 				GPIOD   

//UV灯  热罐加热使能  CAT1复位  蜂鸣器使能
#define UV_LIGHT_CTRL_Pin 									GPIO_PIN_9		 //UV控制
#define UV_LIGHT_CTRL_GPIO_Port 						GPIOA  

#define HEAT_EN_CTRL_Pin 										GPIO_PIN_0		 //热水罐加热使能控制
#define HEAT_EN_CTRL_GPIO_Port 							GPIOE  

#define CAT1_PWR_KEY_CTRL_Pin 							GPIO_PIN_7		 //CAT1复位
#define CAT1_PWR_KEY_CTRL_GPIO_Port 			  GPIOD  

#if (DEV_HARD_VER<=100)

#define BUZZER_EN_CTRL_Pin 							    GPIO_PIN_2		 //蜂鸣器使能
#define BUZZER_EN_CTRL_GPIO_Port 			      GPIOE  

#define LEAK_TDS_FWD_Pin 							    	GPIO_PIN_13		 //漏水TDS正
#define LEAK_TDS_FWD_GPIO_Port 			      	GPIOC  
	
#define LEAK_TDS_REV_Pin 							    	GPIO_PIN_6		 //漏水TDS反
#define LEAK_TDS_REV_GPIO_Port 			      	GPIOE
	
#define SOURCE_TDS_FWD_Pin 							    GPIO_PIN_5	 //源水TDS正
#define SOURCE_TDS_FWD_GPIO_Port 			    	GPIOE
	
#define SOURCE_TDS_REV_Pin 							  	GPIO_PIN_4	 //源水TDS反
#define SOURCE_TDS_REV_GPIO_Port 			      GPIOE  
	
#define PURE_TDS_FWD_Pin 							  		GPIO_PIN_12		 //纯水TDS正
#define PURE_TDS_FWD_GPIO_Port 			    		GPIOD
	
#define PURE_TDS_REV_Pin 							  		GPIO_PIN_13		 //纯水TDS反
#define PURE_TDS_REV_GPIO_Port 			    		GPIOD
	
#define OVER_TDS_FWD_Pin 							  		GPIO_PIN_15	 //水箱溢水位TDS正
#define OVER_TDS_FWD_GPIO_Port 			    		GPIOC
	
#define OVER_TDS_REV_Pin 							  		GPIO_PIN_14 //水箱溢水位TDS反
#define OVER_TDS_REV_GPIO_Port 			    		GPIOC

#define	ADC_CHANNEL_OVER_WATER							ADC_CHANNEL_5/*纯水TDS*/			
#define	ADC_CHANNEL_PURE_TDS								ADC_CHANNEL_6/*水箱溢水位*/				
#define	ADC_CHANNEL_SOURCE_TDS							ADC_CHANNEL_11/*漏水*/ 
#define ADC_CHANNEL_LEAK										ADC_CHANNEL_4/*源水*/ 
	
#else
/*
1. BUZZERP EN 从PE2 改到PB5
2.sourceTDS_IO2从PE6 改到PE3
3.SOURCE TDS_IO1从PC13改到PE4
4.PureTDS_IO2从PC14改到PE5
5.PureTDS_IO1从PC15改到PE6
6.waterLeak_IO2从PE4改到PB9
7.waterLeak_IO1从PE5改到PE2
*/
#define BUZZER_EN_CTRL_Pin 							    GPIO_PIN_5		 //蜂鸣器使能
#define BUZZER_EN_CTRL_GPIO_Port 			      GPIOB 

#define LEAK_TDS_FWD_Pin 							    	GPIO_PIN_2		 //漏水TDS正
#define LEAK_TDS_FWD_GPIO_Port 			      	GPIOE  
	
#define LEAK_TDS_REV_Pin 							    	GPIO_PIN_9		 //漏水TDS反
#define LEAK_TDS_REV_GPIO_Port 			      	GPIOB  
	
#define SOURCE_TDS_FWD_Pin 							  	GPIO_PIN_4		 //源水TDS正
#define SOURCE_TDS_FWD_GPIO_Port 			    	GPIOE
	
#define SOURCE_TDS_REV_Pin 							  	GPIO_PIN_3		 //源水TDS反
#define SOURCE_TDS_REV_GPIO_Port 			    	GPIOE 
	
#define PURE_TDS_FWD_Pin 							  		GPIO_PIN_6		 //纯水TDS正
#define PURE_TDS_FWD_GPIO_Port 			    		GPIOE
	
#define PURE_TDS_REV_Pin 							  		GPIO_PIN_5		 //纯水TDS反
#define PURE_TDS_REV_GPIO_Port 			    		GPIOE
	
#define OVER_TDS_FWD_Pin 							  		GPIO_PIN_12		 //水箱溢水位TDS正
#define OVER_TDS_FWD_GPIO_Port 			    		GPIOD
	
#define OVER_TDS_REV_Pin 							  		GPIO_PIN_13		 //水箱溢水位TDS反
#define OVER_TDS_REV_GPIO_Port 			    		GPIOD

#define	ADC_CHANNEL_OVER_WATER							ADC_CHANNEL_6/*水箱溢水位*/				
#define	ADC_CHANNEL_PURE_TDS								ADC_CHANNEL_5/*纯水TDS*/			
#define	ADC_CHANNEL_SOURCE_TDS							ADC_CHANNEL_4/*源水*/  
#define ADC_CHANNEL_LEAK										ADC_CHANNEL_11/*漏水*/	

#endif


/*未更换引脚前   溢水和纯水  漏水和源水
//漏水TDS 源水TDS 纯水TDS 水箱溢水位 
#define LEAK_TDS_FWD_Pin 							    	GPIO_PIN_5		 //漏水TDS正
#define LEAK_TDS_FWD_GPIO_Port 			      	GPIOE  
	
#define LEAK_TDS_REV_Pin 							    	GPIO_PIN_4		 //漏水TDS反
#define LEAK_TDS_REV_GPIO_Port 			      	GPIOE  
	
#define SOURCE_TDS_FWD_Pin 							  	GPIO_PIN_13		 //源水TDS正
#define SOURCE_TDS_FWD_GPIO_Port 			    	GPIOC
	
#define SOURCE_TDS_REV_Pin 							  	GPIO_PIN_6		 //源水TDS反
#define SOURCE_TDS_REV_GPIO_Port 			    	GPIOE 
	
#define PURE_TDS_FWD_Pin 							  		GPIO_PIN_15		 //纯水TDS正
#define PURE_TDS_FWD_GPIO_Port 			    		GPIOC
	
#define PURE_TDS_REV_Pin 							  		GPIO_PIN_14		 //纯水TDS反
#define PURE_TDS_REV_GPIO_Port 			    		GPIOC
	
#define OVER_TDS_FWD_Pin 							  		GPIO_PIN_12		 //水箱溢水位TDS正
#define OVER_TDS_FWD_GPIO_Port 			    		GPIOD
	
#define OVER_TDS_REV_Pin 							  		GPIO_PIN_13		 //水箱溢水位TDS反
#define OVER_TDS_REV_GPIO_Port 			    		GPIOD

#define	ADC_CHANNEL_OVER_WATER							ADC_CHANNEL_6 //水箱溢水位				
#define	ADC_CHANNEL_PURE_TDS								ADC_CHANNEL_5//纯水TDS		
#define	ADC_CHANNEL_SOURCE_TDS							ADC_CHANNEL_4//源水  
#define ADC_CHANNEL_LEAK										ADC_CHANNEL_11//漏水	

*/
	

	
	
//热罐高中低水位	
#define HEAT_L_TDS_FWD_Pin 							  	GPIO_PIN_12		 //热罐低水位正
#define HEAT_L_TDS_FWD_GPIO_Port 			    	GPIOE
	
#define HEAT_M_TDS_FWD_Pin 							  	GPIO_PIN_15		 //热罐中水位正
#define HEAT_M_TDS_FWD_GPIO_Port 			    	GPIOE
	
#define HEAT_H_TDS_FWD_Pin 							  	GPIO_PIN_14		 //热罐高水位正
#define HEAT_H_TDS_FWD_GPIO_Port 			    	GPIOE
	
#define HEAT_COM_TDS_FWD_Pin 								GPIO_PIN_13		 //热罐公共端
#define HEAT_COM_TDS_FWD_GPIO_Port 			  	GPIOE
	
//模拟IIC  EEPROM  TM1650  气压计	
#define EEPROM_WR_Pin 											GPIO_PIN_15    //EEPROM
#define EEPROM_WR_GPIO_Port 								GPIOB
	
#define EEPROM_SCL_Pin 											GPIO_PIN_2
#define EEPROM_SCL_GPIO_Port 								GPIOA

#define EEPROM_SDA_Pin 											GPIO_PIN_3
#define EEPROM_SDA_GPIO_Port 								GPIOA
	
	
#define TM1650_SCL_Pin 											GPIO_PIN_10    //TM1650
#define TM1650_SCL_GPIO_Port 								GPIOB
	
#define TM1650_SDA_Pin 											GPIO_PIN_11
#define TM1650_SDA_GPIO_Port 								GPIOB
	
#define IIC_AIR_PRE_SCL_Pin 										GPIO_PIN_6    //气压计
#define IIC_AIR_PRE_SCL_GPIO_Port 							GPIOB
	
#define IIC_AIR_PRE_SDA_Pin 										GPIO_PIN_7
#define IIC_AIR_PRE_SDA_GPIO_Port 							GPIOB

/****************************IO输入***********************************************/
//纯水箱浮子输入   高压开关  低压开关
#define FZ_H_Pin 														GPIO_PIN_14     //纯水箱 高水位  //高水位和低水位 标错 20220720 这里直接程序反下GPIO_PIN_12  GPIOB
#define FZ_H_GPIO_Port 											GPIOB
			
#define FZ_M_Pin 														GPIO_PIN_13			//纯水箱 中水位
#define FZ_M_GPIO_Port 											GPIOB
							
#define FZ_L_Pin 														GPIO_PIN_12			//纯水箱 低水位  //高水位和低水位 标错 20220720 这里直接程序反下GPIO_PIN_14 GPIOB
#define FZ_L_GPIO_Port 											GPIOB
			
#define SW_L_Pin 														GPIO_PIN_10      //低压开关
#define SW_L_GPIO_Port 							  			GPIOE
			
#define SW_H_Pin  													GPIO_PIN_9			//高压开关
#define SW_H_GPIO_Port 							  			GPIOE
			
//掉电检测			
#define POWER_CHECK_Pin  						  			GPIO_PIN_1			//掉电检测
#define POWER_CHECK_GPIO_Port 							GPIOE
			
//测试点			
#define TEST1_Pin  						  						GPIO_PIN_8			//测试点1
#define TEST1_GPIO_Port 										GPIOE
			
#define TEST2_Pin  						  						GPIO_PIN_7			//测试点2
#define TEST2_GPIO_Port 										GPIOE

/****************************IO中断***********************************************/
#define RO_FLOW_Pin  						  					GPIO_PIN_11			//流量计
#define RO_FLOW_GPIO_Port 									GPIOE

/****************************ADC检测***********************************************/
//电流检测类   增压泵ADC  常温水隔膜泵ADC 热水泵ADC  UV灯ADC
#define ADC_BOOST_PUMP_Pin 									GPIO_PIN_0     //增压泵ADC
#define ADC_BOOST_PUMP_GPIO_Port 						GPIOC
	
#define ADC_NORMAL_PUMP_Pin 								GPIO_PIN_1     //常温水泵ADC
#define ADC_NORMAL_PUMP_GPIO_Port 					GPIOB
	
#define ADC_HAET_PUMP_Pin 									GPIO_PIN_0     //热水泵ADC
#define ADC_HAET_PUMP_GPIO_Port 						GPIOB

#define ADC_UV_LIGHT_Pin 										GPIO_PIN_1     		//UV灯ADC   遗漏
#define ADC_UV_LIGHT_GPIO_Port 							GPIOA

//NTC类   热罐NTC  纯水NTC   出水NTC
#define ADC_NTC_HEAT_Pin 										GPIO_PIN_4     //热罐ADC
#define ADC_NTC_HEAT_GPIO_Port 							GPIOC

#define ADC_NTC_PURE_Pin 										GPIO_PIN_7     //纯水ADC
#define ADC_NTC_PURE_GPIO_Port 							GPIOA

#define ADC_NTC_WATER_OUT_Pin 							GPIO_PIN_5     //出水NTC
#define ADC_NTC_WATER_OUT_GPIO_Port 				GPIOC

//TDS类  漏水tds_ADC  纯水tds_ADC 源水tds_ADC  纯水箱溢水tds_ADC
#define ADC_OVER_TDS_Pin 										GPIO_PIN_5     //纯水箱溢水tds_ADC
#define ADC_OVER_TDS_GPIO_Port 							GPIOC

#define ADC_PURE_TDS_Pin 										GPIO_PIN_5     //纯水tds_ADC
#define ADC_PURE_TDS_GPIO_Port 							GPIOA

#define ADC_SOURCRE_TDS_Pin 								GPIO_PIN_4     //源水tds_ADC
#define ADC_SOURCRE_TDS_GPIO_Port 					GPIOA

#define ADC_LEAK_TDS_Pin 										GPIO_PIN_1     //漏水tds_ADC
#define ADC_LEAK_TDS_GPIO_Port 							GPIOC

//热罐水位检测类 

#define ADC_HEAT_L_TDS_Pin 									GPIO_PIN_2     //热罐低水位ADC  //配错
#define ADC_HEAT_L_TDS_GPIO_Port 						GPIOC

#define ADC_HEAT_M_TDS_Pin 									GPIO_PIN_3     //热罐中水位ADC  //配错
#define ADC_HEAT_M_TDS_GPIO_Port 						GPIOC

#define ADC_HEAT_H_TDS_Pin 									GPIO_PIN_0     //热罐中水位ADC  //配错
#define ADC_HEAT_H_TDS_GPIO_Port 						GPIOA


	


/****************************USART配置***********************************************/

#define USART_COCK													USART2
#define USART_TX_COCK_Pin 									GPIO_PIN_8     						//龙头串口TX2  U2
#define USART_TX_COCK_GPIO_Port 						GPIOD
#define USART_TX_COCK_DATA_ADDRESS          ((uint32_t)0x40004804)    //USART2数据基地址     

#define USART_RX_COCK_Pin 									GPIO_PIN_9     				   //龙头串口RX2
#define USART_RX_COCK_GPIO_Port 						GPIOD



#define USART_CAT1													USART1
#define USART_TX_CAT1_Pin 									GPIO_PIN_5    					 //CAT1串口TX
#define USART_TX_CAT1_GPIO_Port 						GPIOD
#define USART_TX_CAT1_DATA_ADDRESS          ((uint32_t)0x40004404)    //USART1数据基地址     

#define USART_RX_CAT1_Pin 									GPIO_PIN_6     					//CAT1串口RX
#define USART_RX_CAT1_GPIO_Port 						GPIOD


#define USART_DEBUG													UART3
#define USART_TX_DEBUG_Pin 									GPIO_PIN_10     				//DEBUG串口TX
#define USART_TX_DEBUG_GPIO_Port 						GPIOC
#define USART_TX_DEBUG_DATA_ADDRESS         ((uint32_t)0x40004C04)    //UART3数据基地址     

#define USART_RX_DEBUG_Pin 									GPIO_PIN_11    			   //DEBUG串口RX
#define USART_RX_DEBUG_GPIO_Port 						GPIOC

/****************************PWM配置**********蜂鸣器高频  常温PWM  热水泵PWM*************************************/
#define BUZZER_PWM_Pin 											GPIO_PIN_8     					//蜂鸣器高频口
#define BUZZER_PWM_GPIO_Port 							  GPIOB

#define HeatWater_PUMP_CTR_Pin 							GPIO_PIN_10     					//热水泵PWM
#define HeatWater_PUMP_CTR_GPIO_Port 			  GPIOA

#define NorWater_PUMP_CTR_Pin 							GPIO_PIN_11     					//常温泵PWM
#define NorWater_PUMP_CTR_GPIO_Port 				GPIOA



#define CHIP_ID_ADDR 0x1FFFF7E8
//#define CHIP_ID_ADDR 0x1FFFF7EC
#define HAL_GET_SYSCLOCK_FREQ() SystemCoreClock
//模拟IO操作
#define M_WRITE_PIN(port, pin, x) (x ? (port->BSRR = pin) : (port->BRR = pin))//设置IO状态
#define M_READ_PIN(port, pin) (port->IDR & pin)//读取IO状态
#define M_SET_PIN_IN(port, pin) OnGPIOSetInOut(port, pin, 1)//{SET_BIT(port->INEN, pin);FL_GPIO_SetPinMode(port, pin, FL_GPIO_MODE_INPUT);}//输入模式
#define M_SET_PIN_OUT(port, pin) OnGPIOSetInOut(port, pin, 0)//{CLEAR_BIT(port->INEN, pin);FL_GPIO_SetPinMode(port, pin, FL_GPIO_MODE_OUTPUT);}//输出模式


#define BUZZER_PWM_CMD(x)  timer_channel_output_state_config(TIMER3,TIMER_CH_2,x)

#define ARRAYNUM(arr_name)     (uint32_t)(sizeof(arr_name)/sizeof(*(arr_name)))   //数据个数   在兆易历程中获得


#define HAL_GPIO_WritePin(GPIOx,GPIO_Pin, PinState)    (PinState==1)? (GPIO_BOP(GPIOx)=GPIO_Pin):(GPIO_BC(GPIOx)=GPIO_Pin)
#define HAL_GPIO_ReadPin(GPIOx, GPIO_Pin)   					 (gpio_input_bit_get(GPIOx,GPIO_Pin))


//参数操作宏定义
#define HEAT_WATER_BUMP_PWM_PLUSE(X)    							 timer_channel_output_pulse_value_config(TIMER0,TIMER_CH_2,X)   //热泵占空比
#define NORMAL_WATER_BUMP_PWM_PLUSE(X)   							 timer_channel_output_pulse_value_config(TIMER0,TIMER_CH_3,X)  //冷泵占空比

#define HEAT_PIPE_CTRL_ON()                            HAL_GPIO_WritePin(HEAT_EN_CTRL_GPIO_Port,HEAT_EN_CTRL_Pin, 1) //热罐加热控制   
#define HEAT_PIPE_CTRL_OFF()                           HAL_GPIO_WritePin(HEAT_EN_CTRL_GPIO_Port,HEAT_EN_CTRL_Pin, 0) //热罐加热控制  


#define WASH_ON()           				 HAL_GPIO_WritePin(WASH_CTRL_GPIO_Port,WASH_CTRL_Pin, 1) //冲洗阀    
#define WASH_OFF()         					 HAL_GPIO_WritePin(WASH_CTRL_GPIO_Port,WASH_CTRL_Pin, 0) //冲洗阀  

#define SOURCE_IN_ON()      				 HAL_GPIO_WritePin(SOURCE_IN_CTRL_GPIO_Port,SOURCE_IN_CTRL_Pin, 1) //源水进水阀    
#define SOURCE_IN_OFF()     				 HAL_GPIO_WritePin(SOURCE_IN_CTRL_GPIO_Port,SOURCE_IN_CTRL_Pin, 0) //源水进水阀  

#define BOOST_PUMP_ON()              HAL_GPIO_WritePin(BOOST_PUMP_CTRL_GPIO_Port,BOOST_PUMP_CTRL_Pin, 1) //冲洗阀    
#define BOOST_PUMP_OFF()             HAL_GPIO_WritePin(BOOST_PUMP_CTRL_GPIO_Port,BOOST_PUMP_CTRL_Pin, 0) //冲洗阀  

#define PURE_TANK_IN_ON()            HAL_GPIO_WritePin(PURE_TANK_IN_CTRL_GPIO_Port,PURE_TANK_IN_CTRL_Pin, 1) //纯水箱进水控制阀    
#define PURE_TANK_IN_OFF()           HAL_GPIO_WritePin(PURE_TANK_IN_CTRL_GPIO_Port,PURE_TANK_IN_CTRL_Pin, 0) //纯水箱进水控制阀  

#define PURE_TANK_OUT_ON()           HAL_GPIO_WritePin(PURE_TANK_OUT_CTRL_GPIO_Port,PURE_TANK_OUT_CTRL_Pin, 1) //纯水箱出水控制阀   
#define PURE_TANK_OUT_OFF()          HAL_GPIO_WritePin(PURE_TANK_OUT_CTRL_GPIO_Port,PURE_TANK_OUT_CTRL_Pin, 0) //纯水箱出水控制阀  

#define HEAT_TANK_IN_ON()          	 HAL_GPIO_WritePin(HEAT_TANK_IN_CTRL_GPIO_Port,HEAT_TANK_IN_CTRL_Pin, 1) //热罐进水控制阀  
#define HEAT_TANK_IN_OFF()         	 HAL_GPIO_WritePin(HEAT_TANK_IN_CTRL_GPIO_Port,HEAT_TANK_IN_CTRL_Pin, 0) //热罐进水控制阀

#define HEAT_TANK_OUT_ON()           HAL_GPIO_WritePin(HEAT_TANK_OUT_CTRL_GPIO_Port,HEAT_TANK_OUT_CTRL_Pin, 1) //热罐出水控制阀   备用  
#define HEAT_TANK_OUT_OFF()          HAL_GPIO_WritePin(HEAT_TANK_OUT_CTRL_GPIO_Port,HEAT_TANK_OUT_CTRL_Pin, 0) //热罐出水控制阀   备用

#define UV_LIGHT_ON()           		 HAL_GPIO_WritePin(UV_LIGHT_CTRL_GPIO_Port,UV_LIGHT_CTRL_Pin, 1) //热罐出水控制阀   备用  
#define UV_LIGHT_OFF()         		   HAL_GPIO_WritePin(UV_LIGHT_CTRL_GPIO_Port,UV_LIGHT_CTRL_Pin, 0) //热罐出水控制阀   备用


  
#define LOST_WATER_TIME 120

//GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
//void HAL_UART_Receive_DMA(UARTPortDef port, uint8_t *tbuff, uint16_t tlen);
//void HAL_UART_Transmit_DMA(UARTPortDef port, uint8_t *tbuff, uint16_t tlen);
//void OnIWDT_FeedDog(void);
extern uint32_t OnGetRandomNumber(void);
extern uint64_t HAL_GetTickMs(void);   //获取系统时间
//uint16_t OnGetADCValue(uint32_t channle);
//ErrorStatus MX_IWDT_Init(u8 prescaler);
extern void delayMM(uint16_t nus);
extern void OnSysRestart(void);
extern inline void OnAllOutOff(void);
	
typedef struct
{
	uint8_t lastState;   //保存强制冲洗前的状态 
	uint8_t washFlag ;  //强制冲洗标志
}tsKeyForceWash;  //强制冲洗需要保存的数据

typedef union
{
	uint32_t value;
	struct
	{		
//水箱补水
		uint32_t icheck_high_fz:1;  		  //浮球高液位
		uint32_t icheck_pure_ntc:1;  		  //纯水NTC
		uint32_t icheck_source_tds:1;  		//源水TDS
		uint32_t icheck_pure_tds:1;  		  //纯水TDS
		uint32_t icheck_uv_light:1;  			//UV灯
		uint32_t icheck_flow:1;           //流量计
		uint32_t icheck_high_press_sw:1;  //高压开关
		uint32_t icheck_low_press_sw:1;   //低压开关
		
//热罐补水	
		uint32_t icheck_water_tank_replen_flag:1; 		//水箱补水完成合格标志
		uint32_t res1:4; //预留
		uint32_t icheck_water_tank_all_valve:1;  		  	//增压泵，纯水箱进水阀，源水进水阀
		uint32_t icheck_low_fz:1;  		  	//浮球低液位
		uint32_t icheck_mid_fz:1;  		  	//浮球中液位
		
//热罐加热	

		uint32_t icheck_heat_replen_flag:1;				//热罐补水完成合格标志
		uint32_t res2:3; //预留
		uint32_t icheck_heat_low:1; 							//热罐低液位
		uint32_t icheck_heat_mid:1; 							//热罐中液位
		uint32_t icheck_heat_high:1; 							//热罐高液位
		uint32_t icheck_heat_inwater_valve:1; 		//热罐进水阀
		
//出水及自动手动		
		uint32_t icheck_mode:1;  //0：自检  1：手动检
		uint32_t icheck_self_check_end_flag:1;		//自检合格标志
		uint32_t res3:2; //预留
		uint32_t icheck_heat_out_end_flag:1;			//热罐加热出水
		uint32_t icheck_heat_30s:1;			// 加热30s合格（PDA不需要显示）
		uint32_t icheck_heat_bump:1;							//热水泵
		uint32_t icheck_normal_bump:1;						//常温水泵
	
	} bits;
}tuWaterTestStatus;


typedef struct
{
	uint16_t time25SSD;   //常温水出水时间 
	uint16_t time45SSD ;  //45℃水出水时间 
	uint16_t time75SSD ;  //75℃水出水时间 
	uint16_t time95SSD ;  //95℃水出水时间 
}tsOutWaterCnt;  				//出水时间计时  100ms  根据PID的循环执行




extern uint8_t gCockTestFlag;//龙头测试标志
extern tuWaterTestStatus gWaterTestStatus; //用于水检中的自检
extern tsKeyForceWash gKeyForceWash; //强制冲洗按键
extern	float gBoiling_Point;//沸点
extern  uint8_t gConnectFinish; //0:离线 1:在线
extern  uint8_t gLogDelay; //0: 打印数据； >0 ：用于工装通讯
extern  uint8_t gReStartCnt ; //蓝牙配置成功后   4g的重启次数
extern  uint8_t gSecValue;//时间s
extern  uint8_t gRenameFlag; //蓝牙改名的标志
extern TypeChipInfo gCockInfo; //龙头硬件信息

extern uint8_t gCtrlConnectStatus;//与控制板的连接状态
extern uint8_t gBlueOTAFlag;  //0:未升级  1:升级成功

extern tsOutWaterCnt gOutWaterCnt; //出水时间计时 
#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */

/************************ (C) COPYRIGHT FMSH *****END OF FILE****/
